﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Reflection.Emit;
using System.Dynamic;

using Microsoft.Scripting.Ast;
using Microsoft.Scripting.Utils;

using Scala.Compiler.Ast;
using System.Diagnostics;

namespace Scala.Compiler.Types
{
    public class ILGen
    {
        public static void CreateMethod(DefDefStatement tree, MethodBuilder methBuilder)
        {
            var lambda = tree.Reduce() as LambdaExpression;
            if (lambda == null) throw new Exception("The body of the method is not a function");
            try
            {
                lambda.CompileToMethod(methBuilder);
            }
            catch (Exception e)
            {
                Debug.WriteLine(String.Format("Counldn't generate body for the method {0}, the exception is {1}", tree.Name,e.ToString()));
            }
        }
    }
}
